package org.base23.video.domain.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * 播放指令DTO
 * 定义智能播放器的控制指令
 */
@Data
public class PlaybackInstruction {

    /**
     * 指令ID
     */
    private String instructionId;

    /**
     * 分析结果ID
     */
    private String resultId;

    /**
     * 触发时间点（秒）
     */
    private Double timestamp;

    /**
     * 指令类型
     * PAUSE: 暂停
     * SLOW_MOTION: 慢放
     * NORMAL_SPEED: 正常速度
     * FAST_FORWARD: 快进
     * HIGHLIGHT: 高亮显示
     * EXPLANATION: 讲解说明
     * BOOKMARK: 书签标记
     */
    private InstructionType type;

    /**
     * 播放速度（倍速）
     * 0.25, 0.5, 1.0, 1.5, 2.0 等
     */
    private Double playbackSpeed;

    /**
     * 持续时长（秒）
     * 指令持续的时间，null表示瞬时指令
     */
    private Double duration;

    /**
     * 指令标题
     */
    private String title;

    /**
     * 指令描述/讲解内容
     */
    private String description;

    /**
     * 提示内容
     */
    private String tooltip;

    /**
     * 优先级
     * 1-5，1为最高优先级
     */
    private Integer priority;

    /**
     * 是否自动执行
     */
    private Boolean autoExecute;

    /**
     * 相关的身体部位或关节
     */
    private String relatedBodyPart;

    /**
     * 分析类型
     * POSTURE: 姿态分析
     * MOVEMENT: 动作分析
     * BIOMECHANICS: 生物力学分析
     * TECHNIQUE: 技术分析
     */
    private String analysisType;

    /**
     * 严重程度
     * LOW: 低
     * MEDIUM: 中
     * HIGH: 高
     * CRITICAL: 严重
     */
    private String severity;

    /**
     * 建议改进方案
     */
    private String improvementSuggestion;

    /**
     * 相关视频片段开始时间（秒）
     */
    private Double segmentStartTime;

    /**
     * 相关视频片段结束时间（秒）
     */
    private Double segmentEndTime;

    /**
     * 标签（用于分类和筛选）
     */
    private String[] tags;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    /**
     * 指令类型枚举
     */
    public enum InstructionType {
        PAUSE("暂停"),
        SLOW_MOTION("慢放"),
        NORMAL_SPEED("正常速度"),
        FAST_FORWARD("快进"),
        HIGHLIGHT("高亮显示"),
        EXPLANATION("讲解说明"),
        BOOKMARK("书签标记"),
        WARNING("警告提示"),
        SUGGESTION("建议提示");

        private final String description;

        InstructionType(String description) {
            this.description = description;
        }

        public String getDescription() {
            return description;
        }
    }

    /**
     * 创建暂停指令
     */
    public static PlaybackInstruction createPauseInstruction(String resultId, Double timestamp, String title, String description) {
        PlaybackInstruction instruction = new PlaybackInstruction();
        instruction.setResultId(resultId);
        instruction.setTimestamp(timestamp);
        instruction.setType(InstructionType.PAUSE);
        instruction.setTitle(title);
        instruction.setDescription(description);
        instruction.setAutoExecute(true);
        instruction.setPriority(2);
        instruction.setCreateTime(LocalDateTime.now());
        return instruction;
    }

    /**
     * 创建慢放指令
     */
    public static PlaybackInstruction createSlowMotionInstruction(String resultId, Double timestamp, Double speed, Double duration, String description) {
        PlaybackInstruction instruction = new PlaybackInstruction();
        instruction.setResultId(resultId);
        instruction.setTimestamp(timestamp);
        instruction.setType(InstructionType.SLOW_MOTION);
        instruction.setPlaybackSpeed(speed);
        instruction.setDuration(duration);
        instruction.setDescription(description);
        instruction.setAutoExecute(true);
        instruction.setPriority(1);
        instruction.setCreateTime(LocalDateTime.now());
        return instruction;
    }

    /**
     * 创建讲解指令
     */
    public static PlaybackInstruction createExplanationInstruction(String resultId, Double timestamp, String title, String explanation) {
        PlaybackInstruction instruction = new PlaybackInstruction();
        instruction.setResultId(resultId);
        instruction.setTimestamp(timestamp);
        instruction.setType(InstructionType.EXPLANATION);
        instruction.setTitle(title);
        instruction.setDescription(explanation);
        instruction.setAutoExecute(false);
        instruction.setPriority(3);
        instruction.setCreateTime(LocalDateTime.now());
        return instruction;
    }

    /**
     * 创建高亮指令
     */
    public static PlaybackInstruction createHighlightInstruction(String resultId, Double startTime, Double endTime, String title) {
        PlaybackInstruction instruction = new PlaybackInstruction();
        instruction.setResultId(resultId);
        instruction.setTimestamp(startTime);
        instruction.setType(InstructionType.HIGHLIGHT);
        instruction.setSegmentStartTime(startTime);
        instruction.setSegmentEndTime(endTime);
        instruction.setDuration(endTime - startTime);
        instruction.setTitle(title);
        instruction.setAutoExecute(true);
        instruction.setPriority(2);
        instruction.setCreateTime(LocalDateTime.now());
        return instruction;
    }
} 